#include "Tester.h"

#include "IEC103Type.h"
#include "ClientFactory.h"

Tester::Tester()
{
    m_timerCheckResult.setSingleShot(true);
    connect(&m_timerCheckResult, &QTimer::timeout, this, &Tester::slot_getResult);
}

Tester::~Tester()
{

}

void Tester::NZTester()
{
    // 测试南自设备
    ClientFactory client;
    m_c = client.createNewClient(NZType);
    m_c->connectDevice( "192.168.0.127", "1032", "192.168.0.35", "1048");
    m_c->readDeviceAll();

    m_timerCheckResult.start(8000);
}

void Tester::NRJBTester()
{
    ClientFactory client;
    m_c = client.createNewClient(NRJBType);
    m_c->connectDevice( "192.168.0.220", "192.168.0.35", "6000", "1048" );
    m_c->readDeviceAll();
    m_timerCheckResult.start(6000);
}

void Tester::SZNRTester()
{
    ClientFactory client;
    m_c = client.createNewClient(SZNR);
    m_c->connectDevice( "192.168.0.121", "192.168.0.35", "2420", "1048");
    m_c->readDeviceAll();

    m_timerCheckResult.start(9000);
}

void Tester::slot_getResult()
{
    m_c->getAllBillInfo(m_ret);
    int totalCount = 0 ;
    if ( false == m_ret.isEmpty() ) {
        qDebug() << "定时检查结果获取情况 ：" << m_ret.count() << m_ret.first().groupName;
        for(auto it : m_ret) {
            qDebug() << " *******************************************************************  ";
            qDebug() << "组号" << it.groupNo << ", 组名 " << it.groupName;
            qDebug() << it.billNameList << " | 名字个数 = " << it.billNameList.count();
            qDebug() << it.billRealValueList << " | 值个数 = " << it.billRealValueList.count();
//            qDebug() << it.billTypeList << " | 类型个数 = " << it.billTypeList.count();

            totalCount += it.billNameList.count();
        }
    }

    qDebug() << " ********************总共个数 = " << totalCount << "***********************";
}
